﻿using System;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace PomodoroSuite.FW.Comun.Caching
{
    public static class CacheManager
    {
        /// <summary>
        /// Adds a value to the cache
        /// </summary>
        /// <param name="key">Key for the value</param>
        /// <param name="value">Value to store</param>
        /// <param name="minutesInCache">Minutes that the value will remain in the cache</param>
        public static void AddToCache(string key, object valor, int minutosEnCache)
        {
            CacheSingleton.Instancia.Add(key, valor, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMinutes(minutosEnCache)));
        }

        /// <summary>
        /// Returns a value for its key
        /// </summary>
        /// <param name="key">Key of the value to return</param>
        /// <returns></returns>
        public static object Get(string key)
        {
            return CacheSingleton.Instancia.GetData(key);
        }

        /// <summary>
        /// Removes an element from the cache
        /// </summary>
        /// <param name="key">Key of the value to remove</param>
        public static void Remove(string key)
        {
            CacheSingleton.Instancia.Remove(key);
        }

        /// <summary>
        /// Removes all elements from the cache
        /// </summary>
        public static void Flush()
        {
            CacheSingleton.Instancia.Flush();
        }
    }
}
